// JavaScript Document
var script=new Object()
//浏览器
script.Browser={
	ie:/msie/.test(window.navigator.userAgent.toLowerCase()),
	moz:/gecko/.test(window.navigator.userAgent.toLowerCase()),
	opera:/opera/.test(window.navigator.userAgent.toLowerCase()),
	safari:/safari/.test(window.navigator.userAgent.toLowerCase())
}
//id
script.get={
	id: function(s){return(typeof s=='object')?s:document.getElementById(s);},
	name: function(s){return (typeof s=='object')?s:document.getElementsByName(s);},
	tagname: function (s){return (typeof s=='object')?s:document.getElementsByTagName(s);}
};
//创建一个js引用
script.jsloader={
	// fCallback 要调用的函数
	load:function(sUrl,fCallback){
		var _script=document.createElement('script');
		_script.setAttribute('charset','gb2312');
		_script.setAttribute('type','text/javascript');
		_script.setAttribute('src',sUrl);
		document.getElementsByTagName('head')[0].appendChild(_script);
		if(script.Browser.ie){
			_script.onreadystatechange=function(){
				if(this.readyState=='loaded'||this.readyStaate=='complete'){
					fCallback();
				}
			};
		}else if(script.Browser.moz){
			_script.onload=function(){
				fCallback();
			};
		}else{
			fCallback();
		}
	}
}

//处理cookie
script.Cookie={
	set:function(name,value,expires,path,domain){
		if(typeof expires=="undefined"){
			expires=new Date(new Date().getTime()+24*3600*1000);
		}
		document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"; path=/")+((domain)?";domain="+domain:"");
	},
	get:function(name){
		var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
		if(arr!=null){
			return unescape(arr[2]);
		}
		return null;
	},
	clear:function(name,path,domain){
		if(this.get(name)){
			document.cookie=name+"="+((path)?"; path="+path:"; path=/")+((domain)?"; domain="+domain:"")+";expires=Fri, 02-Jan-1970 00:00:00 GMT";
		}
	}
}


//验证
script.yz={
		isEmail: function(str){
		var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
		return reg.test(str);
		},
		//是否为中文
		isChinase: function (str){
		  var reg = /^[u4E00-u9FA5]+$/;
		  if(!reg.test(str))
		  		return false;
		  else
		  		return true;
		},
		//是否为数字
		isNumber: function(numberstr){
			var reg=/^[0-9]+$/;
			if(!reg.test(numberstr))
				return false;
			else
				return true;
		},
		//验证电话号码和手机
		isTel:function(str){
			if(!/^((13|15|18){1}\d{9}|([0-9]{3,4}\-{1})[1-9]{1}[0-9]{6,7})$/.exec(str)){
				return false;
			}else{
				return true
			}
		},
		//是否为空
		isNull:function (str){
		if (str == "") return true;
			var regu = "^[ ]+$";
			var re = new RegExp(regu);
			return re.test(str);
		}
}

//时间
script.time={
	//获取当前时间 年-月-日 时:分:秒 星期
	tolocalestring:function(htmlid){
			setInterval("document.getElementById('"+htmlid+"').innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
	},
	//获取当前时间 年-月-日
	tolocaledatestring:function(htmlid){
		script.getid(htmlid).innerHTML=new Date().toLocaleDateString();
	},
	//获取当前年份
	getyear:function(){
		return new Date().getYear();
	},
	//获取当前月份
	getmonth:function(){
		return new Date().getMonth();
	},
	//获取前日期
	getday:function(){
		return new Date().getDay();
		
	},
	//获取当前小时数
	gethorus:function(){
		return new Date().getHours();
	},
	//获取当前分钏数
	getminutes:function(){
		return new Date().getMinutes();
	},
	//获取当前秒数
	getseconds:function(){
		return new Date().getSeconds();
	},
	
	//获取当前毫秒数
	getmilliseconds:function(){
		return new Date().getMilliseconds();
	}

	
	
}


script.ajax={
	   get:function(url,callback){
				var request = false;
				try {
					  request = new XMLHttpRequest();
					} catch (trymicrosoft) {
					  try {
						request = new ActiveXObject("Msxml2.XMLHTTP");
					  } catch (othermicrosoft) {
						try {
						  request = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (failed) {
						  request = false;
						}
					  }
					}
				var reg = /\?/;
				if(!url.match(reg)){
					var httpurl=url+"?sid="+Math.random();
				}else{
					var httpurl=url+"&sid="+Math.random();
				}
				request.open("GET", httpurl, true);
				request.onreadystatechange =function(){
					if(request.readyState == 4 && request.status == 200) {
						//var response = request.responseText.split("|"); //获取值后以 | 为分割为数组，赋值给 response
						var response=request.responseText;
						callback(response);	
					}
					
				}
				
			request.send(null);	
		},
		post:function(url,htmlid,params,func){
				var request = false;
					try {
					  request = new XMLHttpRequest();
					} catch (trymicrosoft) {
					  try {
						request = new ActiveXObject("Msxml2.XMLHTTP");
					  } catch (othermicrosoft) {
						try {
						  request = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (failed) {
						  request = false;
						}
					  }
					}
				var reg = /\?/;
				if(!url.match(reg))
				{
					var httpurl=url+"?sid="+Math.random();
				}
				else
				{
					var httpurl=url+"&sid="+Math.random();
				}
				var splitparams,newsparams="";	
				reg_encode=/([^&\?]+)=([^&]+)/ig; 
				if(arrparams=params.match(reg_encode))
				{
					for(var i=0;i<arrparams.length;i++)
					{
						splitparams=arrparams[i].split("=");
						newsparams=newsparams+splitparams[0]+"="+encodeURIComponent(splitparams[1]);
						if(i<arrparams.length-1)
						{
						newsparams=newsparams+"&";
						}
					}
					document.write(newsparams);
				}
				request.open("POST", httpurl, true);
				request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				request.onreadystatechange =function(){
					if(request.readyState == 4 && request.status == 200) {
						//document.getElementById(htmlid).innerHTML=request.responseText; //将值传递给DIV标签	
						var response=request.responseText;
						func(response);
					}
				}
			request.send(params);	
		}
}